{include file="common/head" /}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left" /}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav" /}
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <a href="{:url('fieldAdd',array('moduleid'=>input('id')))}" class="btn btn-xs btn-danger">添加字段</a>
                    </div>
                    <div class="col-xs-12">
                        <form id="fieldorder" name="fieldorder" method="post" action="{:url('listorder')}">
                            <input type="hidden" value="{:input('param.id')}" name="id">
                            <div class="table-responsive">
                                <table id="dynamic-table" class="table table-striped table-bordered table-hover center">
                                    <thead>
                                    <tr>
                                        <th class="center wh90">排序</th>
                                        <th class="center">字段名</th>
                                        <th class="center visible-lg visible-md">别名</th>
                                        <th class="center visible-lg visible-md">字段类型</th>
                                        <th class="center visible-lg visible-md">系统字段</th>
                                        <th class="center">必填</th>
                                        <th class="center" style="border-right:#CCC solid 1px;width: 180px;">管理操作</th>
                                    </tr>
                                    </thead>

                                    <tbody>

                                    {volist name="list" id="vo"}
                                    <tr>
                                        <td><input name="listorders[{$vo.id}]" class="list_order" value="{$vo.listorder}" size="10"/></td>
                                        <td>{$vo.field}</td>
                                        <td class="visible-lg visible-md">{$vo.name}</td>
                                        <td class="visible-lg visible-md">{$vo.type}</td>
                                        <td class="visible-lg visible-md">
                                            {if condition="in_array($vo['field'],$sysfield)"}
                                                <span class="glyphicon glyphicon-ok"></span>
                                            {else /}
                                                <span class="glyphicon glyphicon-remove"></span>
                                            {/if}
                                        </td>
                                        <td>
                                            {if condition="$vo['required'] eq 1"}
                                                <span class="glyphicon glyphicon-ok"></span>
                                            {else /}
                                                <span class="glyphicon glyphicon-remove"></span>
                                            {/if}
                                        </td>

                                        <td>
                                            <div class="action-buttons">
                                                <a class="green" href="{:url('fieldEdit',array('moduleid'=>$vo['moduleid'],'id'=>$vo['id']))}" title="修改">
                                                    修改
                                                </a>
                                                {if condition="$vo['status']==1"}
                                                    {if condition="in_array($vo['field'],$nodostatus)"}
                                                        <font color="#D3D3D3">禁用</font>
                                                    {else /}
                                                        <a href="javascript:" class="zt{$vo.id}" onclick="return stateyes('{$vo.id}');">禁用</a>
                                                    {/if}
                                                {else /}
                                                    <a href="javascript:" class="zt{$vo.id}" onclick="return stateyes('{$vo.id}');"><font color="red">启用</font></a>
                                                {/if}
                                                {if condition="in_array($vo['field'],$sysfield)"}
                                                    <font color="#D3D3D3">删除</font>
                                                    {else /}
                                                    <a href="javascript:" onclick="return del('{$vo.id}');" >删除</a>
                                                {/if}
                                            </div>
                                        </td>
                                    </tr>
                                    {/volist}
                                    <tr>
                                        <td colspan="7" class="text-left">
                                            <button type="submit" id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {include file="common/foot" /}
</div>
<script>
    function del(id) {
        layer.confirm('你确定要删除该字段吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('fieldDel')}?id="+id ;
        });
    }

    function stateyes(id) {
        $.post('{:url("fieldStatus")}', {id: id}, function (data) {
            if (data.status) {
                if (data.info == '状态禁止') {
                    layer.msg(data.info,{icon:5});
                    var a = '<font color="red">启用</font>';
                    $('.zt' + id).html(a);
                    return false;
                } else {
                    layer.msg(data.info,{icon:6});
                    var b = '禁用';
                    $('.zt' + id).html(b);
                    return false;
                }
            }
        });
        return false;
    }
    $(function(){
        $('#fieldorder').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
        }
        function complete(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }else{
                layer.alert(data.info, {icon: 5}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });
</script>
</body>
</html>
